package com.formatos;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.export.JRPdfExporterParameter;

public class PDFReport implements Formato {

	public File escribirReporte(JasperPrint jasperPrint, HttpServletResponse response)
			throws JRException, IOException {
		response.setContentType("application/pdf");
		JRExporter jRExporter = new JRPdfExporter();
		jRExporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
//		byte[] output = JasperExportManager.exportReportToPdf(jasperPrint);
//		response.setContentLength(output.length);
//		ServletOutputStream ouputStream = response.getOutputStream();
//		ouputStream.write(output);
//		ouputStream.flush();
//		ouputStream.close();
//		return output.length;
		return Util.export(jRExporter, "pdf");
	}

	public Object clone() throws CloneNotSupportedException {
		return new PDFReport();
	}
}
